package com.ushio.gougouwangguo.service.impl;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ushio.commonmodule.utils.JwtUtil;
import com.ushio.commonmodule.utils.RedisDbSwitcher;
import com.ushio.gougouwangguo.entity.mysql.*;
import com.ushio.gougouwangguo.entity.qo.ForestExplorationQo;
import com.ushio.gougouwangguo.entity.qo.ResourceListQo;
import com.ushio.gougouwangguo.entity.qo.ResourceSaveQo;
import com.ushio.gougouwangguo.entity.vo.BattleVo;
import com.ushio.gougouwangguo.entity.vo.DogCharacterVo;
import com.ushio.gougouwangguo.entity.vo.ResourceVO;
import com.ushio.gougouwangguo.mapper.*;
import com.ushio.gougouwangguo.service.ResourceService;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author 19451
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService  {

    @Autowired
    ResourceMapper resourceMapper;

    @Autowired
    RedissonClient redissonClient;

    @Autowired
    RedisDbSwitcher redisDbSwitcher;

    @Autowired
    BattleLogServiceImpl battleLogService;
    @Autowired
    BattleLogMapper battleLogMapper;

    @Autowired
    DogCharacterMapper dogCharacterMapper;
    @Autowired
    MonsterMapper monsterMapper;
    @Autowired
    MaterialsBattleLogMapper materialsBattleLogMapper;
    @Autowired
    MaterialsBattleLogServiceImpl materialsBattleLogService;


    @Autowired
    private ObjectMapper objectMapper;


    @Override
    public ResourceVO resourceListQo(ResourceListQo resourceListQo) {



        Resource resourceQo = Resource.builder().userId(resourceListQo.getUserId()).build();

        Resource resource = resourceMapper.resourceListQo(resourceQo);

        ResourceVO resourceVO = ResourceVO.builder().build();

        if (resource!=null){
            BeanUtils.copyProperties(resource,resourceVO);
        }

        return resourceVO;
    }

    @Override
    public void saveResource(ResourceSaveQo resourceListQo) throws JsonProcessingException {

        Resource resource = Resource.builder().build();

        BeanUtils.copyProperties(resourceListQo,resource);

//        RedisTemplate<Object, Object> redisTemplateForDb = redisDbSwitcher.createRedisTemplateForDb(1);
//        String key = "resource";
//
////        ObjectMapper objectMapper  = new ObjectMapper();
//
//        redisTemplateForDb.opsForHash().put(key,resource.getResourceId().toString(), objectMapper.writeValueAsString(resource));

//        RMap<String, Object> map = redissonClient.getMap("resource");
//
//        map.put(resourceListQo.getResourceId().toString(),resource);

        resourceMapper.updateById(resource);

    }




}
